import requests
import json
import pymysql
import xlrd
import time

conn = pymysql.connect(host='192.168.2.205', port=3306, user='jinhuitao', password='jinhuitao_123456',
                       database='sunway_db', charset='utf8')
cursor = conn.cursor()


def excel_s():
    books = xlrd.open_workbook(r"D:/fedex.xlsx")

    sheet = books.sheet_by_index(0)  # sheet_by_index(0)表示为ceshishujvku.xlsx中的第一个表单
    print(f"第一列的内容是:{sheet.col_values(colx=0)}")

    return sheet.col_values(colx=0)


def mysql_s(times, title, describes, Tracking_number):
    newtime = time.strftime('%Y-%m-%d %H:%M:%S')
    cursor.execute(
        "REPLACE into load_fedex set newtime=%s,times=%s,title=%s,describes=%s,Tracking_number=%s",
        [newtime, times, title, describes, Tracking_number])

    conn.commit()


def run():
    for j in excel_s():
        print('跟踪号1', j)
        url = 'https://www.fedex.com/trackingCal/track'
        headers = {
            'Host': 'www.fedex.com',
            # 'Connection': 'keep-alive',
            'Content-Length': '459',
            # 'sec-ch-ua': '"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"',
            # 'Accept': '*/*',
            'ADRUM': 'isAjax:true',
            'sec-ch-ua-mobile': '?0',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
            'Origin': 'https://www.fedex.com',
            'Sec-Fetch-Site': 'same-origin',
            'Sec-Fetch-Mode': 'cors',
            'Sec-Fetch-Dest': 'empty',
            'Referer': 'https://www.fedex.com/zh-cn/home.html',
            'Accept-Encoding': 'gzip, deflate, br',
            'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
            # 'Cookie': 'fdx_cbid=305401236416412883752251160372821; fdx_redirect=zh-cn; isTablet=false; isMobile=false; isWireless=false; Rbt=f0; gdl-clientId=a5192140-b372-4268-a809-adbf1929f4f0; g_sref=(direct); at_check=true; _svtri=ecfb50e7-a67e-409d-8ec8-9fe70a7d53cb; AMCVS_1E22171B520E93BF0A490D44%40AdobeOrg=1; s_ecid=MCMID%7C54992833931412773701780827342782704044; s_cc=true; Nina-nina-fedex-session=%7B%22locale%22%3A%22zh_cn%22%2C%22lcstat%22%3Afalse%7D; SMIDENTITY=idV+qWJkCsdvnztPTVNdiKUjII1sBnA/UUQkhnGeCnPKBIj5QgNUBqkG8r2pgU9zjRlADcyw1UmLM7TUO66UIN5PRJnhpTBqUdEdIcvY7dfivHl5+oALxIO+RMgn3lo4ofj2KHZfcDGb0IQxeWco5VcObWOciOo8NPklIktSbNGQki+z0lySazsYvzAHXXWf1zyn/dfqwD4NDd0ayE7okv45CcjqLW0NSn3kwW8QGsGTssDIQhtiiZUCG1tHVhGCUs2SH/Hfc0aFm9eKkp5MJK8oTl+uw0Atu/kFPaL78dPveJM/MK4C2KJHQ1VYjEwapQkkM8/dKwPfCtS8jKFMib/GCO07OhJhbBhJGVbFhKhRaLF0q+4oYNEUQU+l4B5lIKuqBQ3DdLsILPdAM7ymJFTM1ClOh55q3JcgeJ+kcSgEjDM4+nib+V2pIYVScwH7mtZXowJdDgmrgPZBz6HBzjujl3sEk6cYM98xOiCAm/3sNVt4Q2q7tc0eIQaSiv0lj0dgPzr+tjtl6wejVZVVzsnknsafgBSS; g_stime=1641347636386; mbox=PC#0066215abac045968004549b45edf750.32_0#1704598260|session#a056fd3380174340b3b76e072d059358#1641355319; fdx_locale=zh_CN; setLink=%5B%5BB%5D%5D; PIM-SESSION-ID=NnrlMpgV8A6pP9Fq; siteDC=edc; AMCV_1E22171B520E93BF0A490D44%40AdobeOrg=359503849%7CMCIDTS%7C18997%7CMCMID%7C54992833931412773701780827342782704044%7CMCAAMLH-1641961234%7C11%7CMCAAMB-1641961234%7CRKhpRz8krg2tLO6pguXWp5olkAcUniQYPHaMWWgdJ3xzPWQmdj0y%7CMCOPTOUT-1641363634s%7CNONE%7CMCAID%7CNONE%7CvVersion%7C5.0.1; QSI_HistorySession=https%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641288402174%7Chttps%3A%2F%2Fwww.fedex.com%2Fzh-cn%2Fhome.html~1641347639453%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641349620457%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641349620492%7Chttps%3A%2F%2Fwww.fedex.com%2Fzh-cn%2Fhome.html~1641353460113%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353489994%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353490317%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353750035%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353750248%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355493146%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355493159%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355513873%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355513878%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355627481%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355627492%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641356435278%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641356435505; _abck=886CA23387E220405ABD0C026386EB2B~0~YAAQNtMuF/HyTA1+AQAAX07aKAcDnf87pUAcRv5zmjU2kQ0oXhZsjPj8XBEtQ2HRMj6Y3ArYRE6XguRUDTzuv998/pLGvbGj8/G2NGWbqdS1VyYSuojewjYahsZA4LBSDSeGd/g3nXNJVGN+jITDPXbwqSxgzZujI/hSsVryIvDzZiDLGyu9TsUt5+oeYdd1iFq48AO9kkNTSX74JtTqNYzTj1R8cYIHAJU852Hbu8uuwA/AFFPjJ5TNzgf5vCREOTlHSIT3jn/f9xqtfOsDjRLFlRxEIgXHHSGoKlmAefutQeUVFrVWbv8FFRSsOIpMNn4n8d7AbVDw/yfrvK06pWhGqOiVh4HaujMFULk9N0CdmNLZGydziWaw5qAkODTvZwEddqcKgPb24mB3GusyA/bEgq8NFSI=~-1~-1~-1; ak_bmsc=3B1B1730CEE2B3BD4A625885CA97688E~000000000000000000000000000000~YAAQNtMuF/LyTA1+AQAAX07aKA7ILM72JrXwkPz4UlwskAECbPUZrzeiBc73Y0XnTczADlyV8I7ZBNjOwOh3pycee5Eqv9CJA+/t8KTcV7Qn4K7sIG981Ue7FlNgxwqeHHBQqQ0DrXaRQD17/P178PbqSoiI1rkEZINZAPrjQq2+0pLT2P4TjdwHOGWv2Y62vrBQu9PdZgt5e2c963c56WwK/Cu/s81yaRcwJRJNVmBICBNv6O0MVRhx5EJakyJXIlmSVnGyiGewc8AFSry6T4on5ctGpjJ6NXXB5nDCFSf3uu48Y6QNeK9JTjyWFf5kVZxCKHjVX4sRKB4WAbKP7fGr0GV8ccS2wn3B70xNfTQcN5oSOY9ehdnkGH8=; bm_sz=517985989C7DCBD9291A9826FAF6116D~YAAQNtMuF/PyTA1+AQAAX07aKA6SuAtRC2A/7/bY+fClRzv5STq31ykGHSXbXGXd1fzIx8ljWb1wQsGD/SBsppBR//Zu0qOk0ipd5atx+JQ7uuheWCSezVzwKvIKBZQ1izhMHX+qdy/NdJmao/po9c3euMVOQYZAV7Lpyp2TVllMIeWstzKyKYlJ1YGmp30E0LNcQL7VAVePSGcN8YhBDukINN2gKLgqzHgmojygkofehh6+XsYt33TyG34EUv5YxbQgkSyHg1/lFTAzDw2hHMvS3TU8CXLOC7iqHKtaW7GALQ==~4339250~4535620; s_sess=%20setLink%3D%3B%20s_ppv%3Dfedex%252Fhero%25257Ctrack%252C88%252C47%252C2536%3B%20SC_LINKS%3Dfedex%252Ftrk-detailpage-managedelivery%255E%255E%25E7%25AE%25A1%25E7%2590%2586%25E9%2580%2592%25E9%2580%2581%255E%255Efedex%252Ftrk-detailpage-managedelivery%2520%257C%2520%25E7%25AE%25A1%25E7%2590%2586%25E9%2580%2592%25E9%2580%2581%255E%255E%3B; s_pers=%20s_vnum%3D1641398399999%2526vn%253D4%7C1641398399999%3B%20gpv_pageName%3Dfedex%252Ftrk-detailpage-managedelivery%7C1641364733138%3B%20s_invisit%3Dtrue%7C1641364733147%3B; s_sq=fedexglbl%3D%2526c.%2526a.%2526activitymap.%2526page%253Dfedex%25252Ftrk-detailpage-managedelivery%2526link%253D%2525E7%2525AE%2525A1%2525E7%252590%252586%2525E9%252580%252592%2525E9%252580%252581%2526region%253Dcontainer%2526pageIDType%253D1%2526.activitymap%2526.a%2526.c%2526pid%253Dfedex%25252Ftrk-detailpage-managedelivery%2526pidt%253D1%2526oid%253D%2525E7%2525AE%2525A1%2525E7%252590%252586%2525E9%252580%252592%2525E9%252580%252581%2526oidt%253D3%2526ot%253DSUBMIT; ADRUM=s=1641362944203&r=https%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3F476261820; xacc=CN; aemserver=PROD-P-dotcom-c0016056.prod.cloud.fedex.com; bm_mi=B8EFA7EDF504E14BEE716B87C33A72DB~6UYWZe8ZUe26CWEs8kvvIA7nSLBKORtdDvJCO4E3lMBNZdFCPDyVZ7HGBHJwqEEOrA+cMACq381mNxpNIyljJF+9c9yJiKYrkyHY7ENUjXPP1W6KFnyInYSCHS1bK002EXXUSVn3Vehau4qasIMjCfd5+qb+v7wJT1usYckYSWAnPTX09KdQAkVcZ88kiY91TdXtpe+8uMKEsLX+jRNvWsFdXgUjDlSLLVhw54T0x4ESgvunRyWpkxN2vyF6lmPpR6MYO5rw5fYlJV8qU8jkVmEd78RfzHEudi+FOxOvFUeJJbzizTU94g2TU2UZ5xnb; bm_sv=4D3E7302F82B4D249F1ADB99FB5C8029~OCgNA7VPxKgyF4fZtN9KLCu9cVEab2s+XJkyzoHuBV2QJB0LcXwRZchnjut5jaII4Ork5iPqpfawAp4vBKsLtQcofhgy0Nbh+VRekLhxpf+X8/r8KtNdM01iE7720huo0nftWA74rbz0ccdLsA4GdmsOpm5+S1dBsA3/mM1DMJk='.format(j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j)
        }
        parm1 = {
            'action': 'trackpackages',
            'data': json.dumps({"TrackPackagesRequest": {"appDeviceType": "DESKTOP", "appType": "WTRK",
                                                         "processingParameters": {}, "uniqueKey": "",
                                                         "supportCurrentLocation": True, "supportHTML": True,
                                                         "trackingInfoList": [{"trackNumberInfo": {
                                                             "trackingNumber": "{}".format(j), "trackingQualifier": "",
                                                             "trackingCarrier": ""}}]}}),
            'format': 'json',
            'locale': 'zh_CN',
            'version': '1',

        }

        res1 = requests.post(url, headers=headers, data=parm1, verify=False).json()
        number = res1['TrackPackagesResponse']['packageList'][0]['masterQualifier']  # 2459543000
        print(number)  # masterQualifier  ['scanEventList']
        for i in res1['TrackPackagesResponse']['packageList'][0]['scanEventList']:
            # print(i)
            print('主{}'.format(i))
            print('*' * 30)
            times = i['date'] + ' ' + i['time']
            title = i['status']
            describes = i['scanLocation']
            Tracking_number = j
            mysql_s(times, title, describes, Tracking_number)
        print('#' * 30)
        run1(j, number)


def run1(j, number):
    url = 'https://www.fedex.com/trackingCal/track'
    headers = {
        'Host': 'www.fedex.com',
        # 'Connection': 'keep-alive',
        'Content-Length': '459',
        # 'sec-ch-ua': '"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"',
        # 'Accept': '*/*',
        'ADRUM': 'isAjax:true',
        'sec-ch-ua-mobile': '?0',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'Origin': 'https://www.fedex.com',
        'Sec-Fetch-Site': 'same-origin',
        'Sec-Fetch-Mode': 'cors',
        'Sec-Fetch-Dest': 'empty',
        'Referer': 'https://www.fedex.com/zh-cn/home.html',
        'Accept-Encoding': 'gzip, deflate, br',
        'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
        # 'Cookie': 'fdx_cbid=305401236416412883752251160372821; fdx_redirect=zh-cn; isTablet=false; isMobile=false; isWireless=false; Rbt=f0; gdl-clientId=a5192140-b372-4268-a809-adbf1929f4f0; g_sref=(direct); at_check=true; _svtri=ecfb50e7-a67e-409d-8ec8-9fe70a7d53cb; AMCVS_1E22171B520E93BF0A490D44%40AdobeOrg=1; s_ecid=MCMID%7C54992833931412773701780827342782704044; s_cc=true; Nina-nina-fedex-session=%7B%22locale%22%3A%22zh_cn%22%2C%22lcstat%22%3Afalse%7D; SMIDENTITY=idV+qWJkCsdvnztPTVNdiKUjII1sBnA/UUQkhnGeCnPKBIj5QgNUBqkG8r2pgU9zjRlADcyw1UmLM7TUO66UIN5PRJnhpTBqUdEdIcvY7dfivHl5+oALxIO+RMgn3lo4ofj2KHZfcDGb0IQxeWco5VcObWOciOo8NPklIktSbNGQki+z0lySazsYvzAHXXWf1zyn/dfqwD4NDd0ayE7okv45CcjqLW0NSn3kwW8QGsGTssDIQhtiiZUCG1tHVhGCUs2SH/Hfc0aFm9eKkp5MJK8oTl+uw0Atu/kFPaL78dPveJM/MK4C2KJHQ1VYjEwapQkkM8/dKwPfCtS8jKFMib/GCO07OhJhbBhJGVbFhKhRaLF0q+4oYNEUQU+l4B5lIKuqBQ3DdLsILPdAM7ymJFTM1ClOh55q3JcgeJ+kcSgEjDM4+nib+V2pIYVScwH7mtZXowJdDgmrgPZBz6HBzjujl3sEk6cYM98xOiCAm/3sNVt4Q2q7tc0eIQaSiv0lj0dgPzr+tjtl6wejVZVVzsnknsafgBSS; g_stime=1641347636386; mbox=PC#0066215abac045968004549b45edf750.32_0#1704598260|session#a056fd3380174340b3b76e072d059358#1641355319; fdx_locale=zh_CN; setLink=%5B%5BB%5D%5D; PIM-SESSION-ID=NnrlMpgV8A6pP9Fq; siteDC=edc; AMCV_1E22171B520E93BF0A490D44%40AdobeOrg=359503849%7CMCIDTS%7C18997%7CMCMID%7C54992833931412773701780827342782704044%7CMCAAMLH-1641961234%7C11%7CMCAAMB-1641961234%7CRKhpRz8krg2tLO6pguXWp5olkAcUniQYPHaMWWgdJ3xzPWQmdj0y%7CMCOPTOUT-1641363634s%7CNONE%7CMCAID%7CNONE%7CvVersion%7C5.0.1; QSI_HistorySession=https%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641288402174%7Chttps%3A%2F%2Fwww.fedex.com%2Fzh-cn%2Fhome.html~1641347639453%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641349620457%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641349620492%7Chttps%3A%2F%2Fwww.fedex.com%2Fzh-cn%2Fhome.html~1641353460113%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353489994%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353490317%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353750035%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353750248%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355493146%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355493159%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355513873%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355513878%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355627481%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355627492%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641356435278%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641356435505; _abck=886CA23387E220405ABD0C026386EB2B~0~YAAQNtMuF/HyTA1+AQAAX07aKAcDnf87pUAcRv5zmjU2kQ0oXhZsjPj8XBEtQ2HRMj6Y3ArYRE6XguRUDTzuv998/pLGvbGj8/G2NGWbqdS1VyYSuojewjYahsZA4LBSDSeGd/g3nXNJVGN+jITDPXbwqSxgzZujI/hSsVryIvDzZiDLGyu9TsUt5+oeYdd1iFq48AO9kkNTSX74JtTqNYzTj1R8cYIHAJU852Hbu8uuwA/AFFPjJ5TNzgf5vCREOTlHSIT3jn/f9xqtfOsDjRLFlRxEIgXHHSGoKlmAefutQeUVFrVWbv8FFRSsOIpMNn4n8d7AbVDw/yfrvK06pWhGqOiVh4HaujMFULk9N0CdmNLZGydziWaw5qAkODTvZwEddqcKgPb24mB3GusyA/bEgq8NFSI=~-1~-1~-1; ak_bmsc=3B1B1730CEE2B3BD4A625885CA97688E~000000000000000000000000000000~YAAQNtMuF/LyTA1+AQAAX07aKA7ILM72JrXwkPz4UlwskAECbPUZrzeiBc73Y0XnTczADlyV8I7ZBNjOwOh3pycee5Eqv9CJA+/t8KTcV7Qn4K7sIG981Ue7FlNgxwqeHHBQqQ0DrXaRQD17/P178PbqSoiI1rkEZINZAPrjQq2+0pLT2P4TjdwHOGWv2Y62vrBQu9PdZgt5e2c963c56WwK/Cu/s81yaRcwJRJNVmBICBNv6O0MVRhx5EJakyJXIlmSVnGyiGewc8AFSry6T4on5ctGpjJ6NXXB5nDCFSf3uu48Y6QNeK9JTjyWFf5kVZxCKHjVX4sRKB4WAbKP7fGr0GV8ccS2wn3B70xNfTQcN5oSOY9ehdnkGH8=; bm_sz=517985989C7DCBD9291A9826FAF6116D~YAAQNtMuF/PyTA1+AQAAX07aKA6SuAtRC2A/7/bY+fClRzv5STq31ykGHSXbXGXd1fzIx8ljWb1wQsGD/SBsppBR//Zu0qOk0ipd5atx+JQ7uuheWCSezVzwKvIKBZQ1izhMHX+qdy/NdJmao/po9c3euMVOQYZAV7Lpyp2TVllMIeWstzKyKYlJ1YGmp30E0LNcQL7VAVePSGcN8YhBDukINN2gKLgqzHgmojygkofehh6+XsYt33TyG34EUv5YxbQgkSyHg1/lFTAzDw2hHMvS3TU8CXLOC7iqHKtaW7GALQ==~4339250~4535620; s_sess=%20setLink%3D%3B%20s_ppv%3Dfedex%252Fhero%25257Ctrack%252C88%252C47%252C2536%3B%20SC_LINKS%3Dfedex%252Ftrk-detailpage-managedelivery%255E%255E%25E7%25AE%25A1%25E7%2590%2586%25E9%2580%2592%25E9%2580%2581%255E%255Efedex%252Ftrk-detailpage-managedelivery%2520%257C%2520%25E7%25AE%25A1%25E7%2590%2586%25E9%2580%2592%25E9%2580%2581%255E%255E%3B; s_pers=%20s_vnum%3D1641398399999%2526vn%253D4%7C1641398399999%3B%20gpv_pageName%3Dfedex%252Ftrk-detailpage-managedelivery%7C1641364733138%3B%20s_invisit%3Dtrue%7C1641364733147%3B; s_sq=fedexglbl%3D%2526c.%2526a.%2526activitymap.%2526page%253Dfedex%25252Ftrk-detailpage-managedelivery%2526link%253D%2525E7%2525AE%2525A1%2525E7%252590%252586%2525E9%252580%252592%2525E9%252580%252581%2526region%253Dcontainer%2526pageIDType%253D1%2526.activitymap%2526.a%2526.c%2526pid%253Dfedex%25252Ftrk-detailpage-managedelivery%2526pidt%253D1%2526oid%253D%2525E7%2525AE%2525A1%2525E7%252590%252586%2525E9%252580%252592%2525E9%252580%252581%2526oidt%253D3%2526ot%253DSUBMIT; ADRUM=s=1641362944203&r=https%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3F476261820; xacc=CN; aemserver=PROD-P-dotcom-c0016056.prod.cloud.fedex.com; bm_mi=B8EFA7EDF504E14BEE716B87C33A72DB~6UYWZe8ZUe26CWEs8kvvIA7nSLBKORtdDvJCO4E3lMBNZdFCPDyVZ7HGBHJwqEEOrA+cMACq381mNxpNIyljJF+9c9yJiKYrkyHY7ENUjXPP1W6KFnyInYSCHS1bK002EXXUSVn3Vehau4qasIMjCfd5+qb+v7wJT1usYckYSWAnPTX09KdQAkVcZ88kiY91TdXtpe+8uMKEsLX+jRNvWsFdXgUjDlSLLVhw54T0x4ESgvunRyWpkxN2vyF6lmPpR6MYO5rw5fYlJV8qU8jkVmEd78RfzHEudi+FOxOvFUeJJbzizTU94g2TU2UZ5xnb; bm_sv=4D3E7302F82B4D249F1ADB99FB5C8029~OCgNA7VPxKgyF4fZtN9KLCu9cVEab2s+XJkyzoHuBV2QJB0LcXwRZchnjut5jaII4Ork5iPqpfawAp4vBKsLtQcofhgy0Nbh+VRekLhxpf+X8/r8KtNdM01iE7720huo0nftWA74rbz0ccdLsA4GdmsOpm5+S1dBsA3/mM1DMJk='.format(j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j)
    }
    parm1 = {
        'action': 'getAssociatedShipments',
        'data': json.dumps({"AssociatedShipmentRequest": {"appDeviceType": "DESKTOP", "appType": "WTRK",
                                                          "processingParameters": {}, "uniqueKey": "",
                                                          "masterTrackingNumberInfo": {"associatedType": "MPS",
                                                                                       "trackingNumberInfo": {
                                                                                           "trackingCarrier": "",
                                                                                           "trackingNumber": "{}".format(
                                                                                               j),
                                                                                           "trackingQualifier": "{}".format(
                                                                                               number)}}}}),
        'format': 'json',
        'locale': 'zh_CN',
        'version': '1',

    }

    res1 = requests.post(url, headers=headers, data=parm1, verify=False).json()
    # print(res1)
    for i in res1['AssociatedShipmentsResponse']['associatedShipmentList'][1:]:
        # print(i['trackingNbr'])
        track = i['trackingNbr']
        run2(track)


def run2(track):
    print('跟踪号2', track)
    url = 'https://www.fedex.com/trackingCal/track'
    headers = {
        'Host': 'www.fedex.com',
        # 'Connection': 'keep-alive',
        'Content-Length': '459',
        # 'sec-ch-ua': '"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"',
        # 'Accept': '*/*',
        'ADRUM': 'isAjax:true',
        'sec-ch-ua-mobile': '?0',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'Origin': 'https://www.fedex.com',
        'Sec-Fetch-Site': 'same-origin',
        'Sec-Fetch-Mode': 'cors',
        'Sec-Fetch-Dest': 'empty',
        'Referer': 'https://www.fedex.com/zh-cn/home.html',
        'Accept-Encoding': 'gzip, deflate, br',
        'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
        # 'Cookie': 'fdx_cbid=305401236416412883752251160372821; fdx_redirect=zh-cn; isTablet=false; isMobile=false; isWireless=false; Rbt=f0; gdl-clientId=a5192140-b372-4268-a809-adbf1929f4f0; g_sref=(direct); at_check=true; _svtri=ecfb50e7-a67e-409d-8ec8-9fe70a7d53cb; AMCVS_1E22171B520E93BF0A490D44%40AdobeOrg=1; s_ecid=MCMID%7C54992833931412773701780827342782704044; s_cc=true; Nina-nina-fedex-session=%7B%22locale%22%3A%22zh_cn%22%2C%22lcstat%22%3Afalse%7D; SMIDENTITY=idV+qWJkCsdvnztPTVNdiKUjII1sBnA/UUQkhnGeCnPKBIj5QgNUBqkG8r2pgU9zjRlADcyw1UmLM7TUO66UIN5PRJnhpTBqUdEdIcvY7dfivHl5+oALxIO+RMgn3lo4ofj2KHZfcDGb0IQxeWco5VcObWOciOo8NPklIktSbNGQki+z0lySazsYvzAHXXWf1zyn/dfqwD4NDd0ayE7okv45CcjqLW0NSn3kwW8QGsGTssDIQhtiiZUCG1tHVhGCUs2SH/Hfc0aFm9eKkp5MJK8oTl+uw0Atu/kFPaL78dPveJM/MK4C2KJHQ1VYjEwapQkkM8/dKwPfCtS8jKFMib/GCO07OhJhbBhJGVbFhKhRaLF0q+4oYNEUQU+l4B5lIKuqBQ3DdLsILPdAM7ymJFTM1ClOh55q3JcgeJ+kcSgEjDM4+nib+V2pIYVScwH7mtZXowJdDgmrgPZBz6HBzjujl3sEk6cYM98xOiCAm/3sNVt4Q2q7tc0eIQaSiv0lj0dgPzr+tjtl6wejVZVVzsnknsafgBSS; g_stime=1641347636386; mbox=PC#0066215abac045968004549b45edf750.32_0#1704598260|session#a056fd3380174340b3b76e072d059358#1641355319; fdx_locale=zh_CN; setLink=%5B%5BB%5D%5D; PIM-SESSION-ID=NnrlMpgV8A6pP9Fq; siteDC=edc; AMCV_1E22171B520E93BF0A490D44%40AdobeOrg=359503849%7CMCIDTS%7C18997%7CMCMID%7C54992833931412773701780827342782704044%7CMCAAMLH-1641961234%7C11%7CMCAAMB-1641961234%7CRKhpRz8krg2tLO6pguXWp5olkAcUniQYPHaMWWgdJ3xzPWQmdj0y%7CMCOPTOUT-1641363634s%7CNONE%7CMCAID%7CNONE%7CvVersion%7C5.0.1; QSI_HistorySession=https%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641288402174%7Chttps%3A%2F%2Fwww.fedex.com%2Fzh-cn%2Fhome.html~1641347639453%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641349620457%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641349620492%7Chttps%3A%2F%2Fwww.fedex.com%2Fzh-cn%2Fhome.html~1641353460113%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353489994%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353490317%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353750035%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353750248%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355493146%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355493159%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355513873%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355513878%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355627481%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355627492%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641356435278%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641356435505; _abck=886CA23387E220405ABD0C026386EB2B~0~YAAQNtMuF/HyTA1+AQAAX07aKAcDnf87pUAcRv5zmjU2kQ0oXhZsjPj8XBEtQ2HRMj6Y3ArYRE6XguRUDTzuv998/pLGvbGj8/G2NGWbqdS1VyYSuojewjYahsZA4LBSDSeGd/g3nXNJVGN+jITDPXbwqSxgzZujI/hSsVryIvDzZiDLGyu9TsUt5+oeYdd1iFq48AO9kkNTSX74JtTqNYzTj1R8cYIHAJU852Hbu8uuwA/AFFPjJ5TNzgf5vCREOTlHSIT3jn/f9xqtfOsDjRLFlRxEIgXHHSGoKlmAefutQeUVFrVWbv8FFRSsOIpMNn4n8d7AbVDw/yfrvK06pWhGqOiVh4HaujMFULk9N0CdmNLZGydziWaw5qAkODTvZwEddqcKgPb24mB3GusyA/bEgq8NFSI=~-1~-1~-1; ak_bmsc=3B1B1730CEE2B3BD4A625885CA97688E~000000000000000000000000000000~YAAQNtMuF/LyTA1+AQAAX07aKA7ILM72JrXwkPz4UlwskAECbPUZrzeiBc73Y0XnTczADlyV8I7ZBNjOwOh3pycee5Eqv9CJA+/t8KTcV7Qn4K7sIG981Ue7FlNgxwqeHHBQqQ0DrXaRQD17/P178PbqSoiI1rkEZINZAPrjQq2+0pLT2P4TjdwHOGWv2Y62vrBQu9PdZgt5e2c963c56WwK/Cu/s81yaRcwJRJNVmBICBNv6O0MVRhx5EJakyJXIlmSVnGyiGewc8AFSry6T4on5ctGpjJ6NXXB5nDCFSf3uu48Y6QNeK9JTjyWFf5kVZxCKHjVX4sRKB4WAbKP7fGr0GV8ccS2wn3B70xNfTQcN5oSOY9ehdnkGH8=; bm_sz=517985989C7DCBD9291A9826FAF6116D~YAAQNtMuF/PyTA1+AQAAX07aKA6SuAtRC2A/7/bY+fClRzv5STq31ykGHSXbXGXd1fzIx8ljWb1wQsGD/SBsppBR//Zu0qOk0ipd5atx+JQ7uuheWCSezVzwKvIKBZQ1izhMHX+qdy/NdJmao/po9c3euMVOQYZAV7Lpyp2TVllMIeWstzKyKYlJ1YGmp30E0LNcQL7VAVePSGcN8YhBDukINN2gKLgqzHgmojygkofehh6+XsYt33TyG34EUv5YxbQgkSyHg1/lFTAzDw2hHMvS3TU8CXLOC7iqHKtaW7GALQ==~4339250~4535620; s_sess=%20setLink%3D%3B%20s_ppv%3Dfedex%252Fhero%25257Ctrack%252C88%252C47%252C2536%3B%20SC_LINKS%3Dfedex%252Ftrk-detailpage-managedelivery%255E%255E%25E7%25AE%25A1%25E7%2590%2586%25E9%2580%2592%25E9%2580%2581%255E%255Efedex%252Ftrk-detailpage-managedelivery%2520%257C%2520%25E7%25AE%25A1%25E7%2590%2586%25E9%2580%2592%25E9%2580%2581%255E%255E%3B; s_pers=%20s_vnum%3D1641398399999%2526vn%253D4%7C1641398399999%3B%20gpv_pageName%3Dfedex%252Ftrk-detailpage-managedelivery%7C1641364733138%3B%20s_invisit%3Dtrue%7C1641364733147%3B; s_sq=fedexglbl%3D%2526c.%2526a.%2526activitymap.%2526page%253Dfedex%25252Ftrk-detailpage-managedelivery%2526link%253D%2525E7%2525AE%2525A1%2525E7%252590%252586%2525E9%252580%252592%2525E9%252580%252581%2526region%253Dcontainer%2526pageIDType%253D1%2526.activitymap%2526.a%2526.c%2526pid%253Dfedex%25252Ftrk-detailpage-managedelivery%2526pidt%253D1%2526oid%253D%2525E7%2525AE%2525A1%2525E7%252590%252586%2525E9%252580%252592%2525E9%252580%252581%2526oidt%253D3%2526ot%253DSUBMIT; ADRUM=s=1641362944203&r=https%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3F476261820; xacc=CN; aemserver=PROD-P-dotcom-c0016056.prod.cloud.fedex.com; bm_mi=B8EFA7EDF504E14BEE716B87C33A72DB~6UYWZe8ZUe26CWEs8kvvIA7nSLBKORtdDvJCO4E3lMBNZdFCPDyVZ7HGBHJwqEEOrA+cMACq381mNxpNIyljJF+9c9yJiKYrkyHY7ENUjXPP1W6KFnyInYSCHS1bK002EXXUSVn3Vehau4qasIMjCfd5+qb+v7wJT1usYckYSWAnPTX09KdQAkVcZ88kiY91TdXtpe+8uMKEsLX+jRNvWsFdXgUjDlSLLVhw54T0x4ESgvunRyWpkxN2vyF6lmPpR6MYO5rw5fYlJV8qU8jkVmEd78RfzHEudi+FOxOvFUeJJbzizTU94g2TU2UZ5xnb; bm_sv=4D3E7302F82B4D249F1ADB99FB5C8029~OCgNA7VPxKgyF4fZtN9KLCu9cVEab2s+XJkyzoHuBV2QJB0LcXwRZchnjut5jaII4Ork5iPqpfawAp4vBKsLtQcofhgy0Nbh+VRekLhxpf+X8/r8KtNdM01iE7720huo0nftWA74rbz0ccdLsA4GdmsOpm5+S1dBsA3/mM1DMJk='.format(j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j)
    }
    parm1 = {
        'action': 'trackpackages',
        'data': json.dumps({"TrackPackagesRequest": {"appDeviceType": "DESKTOP", "appType": "WTRK",
                                                     "processingParameters": {}, "uniqueKey": "",
                                                     "supportCurrentLocation": True, "supportHTML": True,
                                                     "trackingInfoList": [{"trackNumberInfo": {
                                                         "trackingNumber": "{}".format(track), "trackingQualifier": "",
                                                         "trackingCarrier": ""}}]}}),
        'format': 'json',
        'locale': 'zh_CN',
        'version': '1',

    }

    res1 = requests.post(url, headers=headers, data=parm1, verify=False).json()
    for i in res1['TrackPackagesResponse']['packageList'][0]['scanEventList']:
        # print(i)
        times = i['date'] + ' ' + i['time']
        title = i['status']
        describes = i['scanLocation']
        Tracking_number = track
        mysql_s(times, title, describes, Tracking_number)


if __name__ == '__main__':
    run()
